# 导包
import random
import re
from unit_tools.handle_data.yaml_handler import get_extract_yaml


class DebugTalk:

    def get_extract_data(self, node_name, out_format=None):
        data = get_extract_yaml(node_name)
        if out_format is not None and bool(re.compile(r'^[+-]?\d+$').match(str(out_format))):
            out_format = int(out_format)
            data_value = {
                out_format: self.seq_read(data, out_format),
                0: random.choice(data),
                -1: ','.join(data),
                -2: ','.join(data).split(',')
            }
            data = data_value[out_format]
        else:
            data = get_extract_yaml(node_name, out_format)
        return data


    def seq_read(self, data, out_format):
        if out_format not in [0, -1, -2]:
            return data[out_format - 1]
        else:
            return None

    def params_md5(self):
        pass


    def get_now_time(self):
        return '999'


    def get_headers(self, params_type):
        headers_mapping = {
            'data': {'Content-Type': 'application/x-www-formurlencoded;charset=UTF-8'},
            'json': {'Content-Type': 'application/json;charset=UTF-8'}
        }
        header = headers_mapping.get(params_type)
        if header is None:
            raise ValueError('不支持其他类型的请求头设置！')
        return header


if __name__ == '__main__':
    debug = DebugTalk()
    res = debug.get_extract_data('Cookie', 'access_token_cookie')
    print(res)